#include "spriteanim.h"

spriteanim spriteanims[2][128];

void setSpriteAnim(int screen,int idsprite,int nbframe,int speed){	
	spriteanims[screen][idsprite].currentframe = 0;
	spriteanims[screen][idsprite].lastframe = nbframe;
	spriteanims[screen][idsprite].speed = speed;	
	spriteanims[screen][idsprite].time = 0;
	spriteanims[screen][idsprite].play = 1;
	
}

void updateAnim(){
	int screen;
	int idsprite;
	for (screen = 0; screen < 2; screen++){
		for(idsprite=0;idsprite<128;idsprite++){
			if( spriteanims[screen][idsprite].play == 1){
				spriteanims[screen][idsprite].time ++;
				if(spriteanims[screen][idsprite].time >= spriteanims[screen][idsprite].speed){
					spriteanims[screen][idsprite].time=0;
					spriteanims[screen][idsprite].currentframe++;
					if(spriteanims[screen][idsprite].currentframe >= spriteanims[screen][idsprite].lastframe)
						spriteanims[screen][idsprite].currentframe=0;
					NF_SpriteFrame(screen, idsprite, spriteanims[screen][idsprite].currentframe);
				}
			}
		}
	}
}

void delteSpriteAnim(int screen,int idsprite){
	spriteanims[screen][idsprite].currentframe = 0;
	spriteanims[screen][idsprite].lastframe = 0;
	spriteanims[screen][idsprite].speed = 0;	
	spriteanims[screen][idsprite].time = 0;
	spriteanims[screen][idsprite].play = 0;
}